package com.cipta.lomob.fragments;

import java.util.LinkedList;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.cipta.lomob.R;
import com.cipta.lomob.adapter.AdapterUsers;
import com.cipta.lomob.base.BaseFragment;
import com.cipta.lomob.model.Users;
import com.cipta.lomob.utils.SampleData;

public class UserInviteFragment extends BaseFragment{
	private ListView lvInvite;
	private ProgressBar indicator;
	public static String FRAGMENT_TAG = "UserInviteFragment";
	private LinkedList<Users> listUser;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		initializeLibs();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_user_invite, container, false);
		initializeViews(view);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		initializeProcess();
		initializeActions();
	}
	
	@Override
	public void initializeViews(View view) {
		// TODO Auto-generated method stub
		super.initializeViews(view);
		setHasOptionsMenu(true);
		getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
		lvInvite = (ListView)view.findViewById(R.id.lv_user_infite);
		indicator = (ProgressBar)view.findViewById(R.id.pb_indicator);
	}
	
	@Override
	public void initializeProcess() {
		// TODO Auto-generated method stub
		super.initializeProcess();
		
		lvInvite.setVisibility(View.VISIBLE);
		
		View header = getActivity().getLayoutInflater().inflate(R.layout.header_user_invite, null);
		lvInvite.addHeaderView(header);
		
		Users users = null;
		listUser = new LinkedList<Users>();
		for (int i = 0; i < SampleData.sampleFriends.length; i++) {
			users = new Users();
			users.setName(SampleData.sampleFriends[i][0]);
			users.setTotalMomments(Integer.parseInt(SampleData.sampleFriends[i][1]));
			users.setTotalFollowing(Integer.parseInt(SampleData.sampleFriends[i][2]));
			users.setTotalFollowers(Integer.parseInt(SampleData.sampleFriends[i][3]));
			users.setFollowing(Boolean.parseBoolean(SampleData.sampleFriends[i][4]));
			users.setAvatar("");
			
			listUser.add(users);
		}
		
		AdapterUsers adapterUsers = new AdapterUsers(getActivity(), listUser);
		lvInvite.setAdapter(adapterUsers);
	}
	
	@Override
	public void initializeActions() {
		// TODO Auto-generated method stub
		super.initializeActions();
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if (item.getItemId()==android.R.id.home) {
			Toast.makeText(getActivity(), "Back", Toast.LENGTH_LONG).show();
		}
		return super.onOptionsItemSelected(item);
	}
}
